package com.yuhs.zixing.study.spring.boot.mybatis.controller;

import com.alibaba.fastjson.JSON;
import com.yuhs.zixing.study.spring.boot.mybatis.generator.dto.PayConfigAppDO;
import com.yuhs.zixing.study.spring.boot.mybatis.generator.mapper.PayConfigAppMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;

/**
 * @description: mybatis 测试控制器
 * @author: yuhs
 * @date: 2022/5/16
 */
@RestController
@RequestMapping("/mybatis/test")
public class MybatisTestController {
    @Resource
    PayConfigAppMapper payConfigAppMapper;


    @RequestMapping("/insert")
    public String testInsert(@RequestBody PayConfigAppDO payConfigAppDO) {
        payConfigAppDO.setGmtCreated(new Date());
        payConfigAppDO.setGmtDeleted(new Date());
        payConfigAppDO.setGmtModified(new Date());
        payConfigAppDO.setIsDeleted(0);
        int insert = payConfigAppMapper.insert(payConfigAppDO);
        return JSON.toJSONString(payConfigAppDO);
    }

    @RequestMapping("/update")
    public String testUpdate(@RequestBody PayConfigAppDO payConfigAppDO) {
        payConfigAppDO.setGmtModified(new Date());
        payConfigAppMapper.updateByPrimaryKey(payConfigAppDO);
        return JSON.toJSONString(payConfigAppDO);
    }


}
